﻿using ConfExpert.Forms.Base;
using DevExpress.Utils;
using DevTeam;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace ConfExpert.Forms.Du4
{
    public partial class GomlekFiyati : XForm
    {
        public GomlekFiyati()
        {
            InitializeComponent();
        }

        BindingSource bs;
        //BindingSource bsO;
        private void GomlekFiyati_Load(object sender, EventArgs e)
        {
            
            txtInfo.Caption = "GömlekFiyatı = KumaşFiyatı * 1.08 * X + Y + Z";
            TAM.DU4GomlekFiyatTableAdapter = new Datasets.MyDataTableAdapters.DU4GomlekFiyatTableAdapter();

            bs = new BindingSource(ds, "DU4GomlekFiyat");
            //bsO = new BindingSource(bs, "FK_DU4Orders_DU4GomlekFiyat_ModellNo");
            //ds.DU4GomlekFiyat.Columns.Add("LineCount", typeof(int), "COUNT(Child(FK_DU4Orders_DU4GomlekFiyat_ModellNo).idx)");
            AddBsToList(bs);

            InitGridView(gridView1, bs);
            //InitGridView(gridView2, bsO);
            //gridView2.OptionsBehavior.Editable = false;

            //AddSummary(gridView1, "LineCount");
            //AddSummary(gridView2, "TotalPerPlan");

            GetDetails("DU4GomlekFiyat", "GetDU4GomlekFiyat", 0);
            gridView1.Columns["X"].Caption = "X kats.";
            gridView1.Columns["Y"].Caption = "Y kats.";
            gridView1.Columns["Z"].Caption = "Z kats.";
            //gridView1.ActiveFilterString = "Blatt = '1-14'";
            gridView1.BestFitColumns();
            //gridView2.BestFitColumns();

            splitContainerControl1.AutoSize();
            //bs.CurrentChanged += new EventHandler(bs_CurrentChanged);

            btnKaydet.Visibility = ytk(128) ? DevExpress.XtraBars.BarItemVisibility.Always :  DevExpress.XtraBars.BarItemVisibility.Never ;
            btnKaydet.ItemClick += btnKaydet_ItemClick;

            gridView1.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gridView1_RowCellStyle);
            gridView1.ShowingEditor += new System.ComponentModel.CancelEventHandler(gridView1_ShowingEditor);
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //ds.DU4GomlekFiyat.Columns["LineCount"].Expression = string.Empty;
            Save();
            //ds.DU4GomlekFiyat.Columns["LineCount"].Expression = "COUNT(Child(FK_DU4Orders_DU4GomlekFiyat_ModellNo).idx)";
        }

        void gridView1_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = gridView1.FocusedColumn.FieldName == "ModellNo";
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.Column.FieldName == "ModellNo")
                e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
        }

        //void bs_CurrentChanged(object sender, EventArgs e)
        //{
        //    gridView2.BestFitColumns();
        //}

    }
}